#####
# Replication for: "Can Political Speech Foster Tolerance of Immigrants?" by Schleiter, Tavits, and Ward.
# Various small results reported in main text
#####

library(here)
library(data.table)

# Pre-test respondents spent roughly 80 seconds reading the treatments.. (p.12)

if(!exists("pretest")){
  pretest <- fread(here("data", "pretest.csv"))
}

pretest[ , median(Duration)]

# Pre-test results reported in SI 7 show that 72% of respondents attributed the quotes to Democrats, 8% to Republicans, and 19% to politicians from both parties. (p.13)

partyCounts <- as.matrix(pretest[ , sapply(.SD, table), .SDcols = c("CH_pr", "NM_pr", "CS_pr") ])
rowSums(partyCounts)/sum(partyCounts)

# Respondent comprehension of treatments was generally high: on average, respondents answered 2.27 (out of 3) questions correctly. (p. 17)

# load the pooled data if not already in workspace
if(!exists("pooled")){
  pooled <- fread(here("data", "pooled.csv"))
}

pooled[replication == 0 & Treatment != "Sleep", mean(attention_1 + attention_2 + attention_3)]

#Footnote 14: Respondents in the Control group gave 2.50 correct answers, on average.

pooled[replication == 0 & Treatment == "Sleep", mean(attention_1 + attention_2 + attention_3)]

# Split by treatment, the average numbers of correct answers in the Common Humanity, Norms, and Countering Stereotypes groups were 2.30, 2.19, and 2.31, respectively. (p.17)

pooled[replication == 0 & Treatment != "Sleep", mean(attention_1 + attention_2 + attention_3), by = Treatment]

# They spent an average of 95 seconds reading the instructions, and 70% of them changed the number of tokens they gave across rounds. (p.24)

if(!exists("behav")){
  behav <- fread(here("data", "behav.csv"))
}

behav[game_NR == 1, mean(readTime, na.rm = T)]

# ...and 70% of them changed the number of tokens they gave across rounds.  (p. 24)

behav[ , uniqueN(tokens), by = ResponseId][ , mean(V1 != 1)]

